;;;  DESCOMPOSITION  DESCOMPOSITION  DESCOMPOSITION
;;;  DESCOMPOSITION  DESCOMPOSITION  DESCOMPOSITION
;;;  DESCOMPOSITION  DESCOMPOSITION  DESCOMPOSITION


(defvar *hash-table* (make-hash-table :test 'equal))

(defun delete-element-of-position (simplex i)
  (cond ((= i 0) (cdr simplex))
        (t (cons (car simplex) (delete-element-of-position (cdr simplex) (1- i))))))

(defun faces-of-simplicial (simplicial)
  (declare (cons simplicial))
  (let ((faces '())
        (dim (length simplicial)))
    (do ((i 0 (1+ i)))
        ((= i dim) faces)
      (if (gethash (delete-element-of-position simplicial i) *hash-table*)
              ()
            (progn (setf faces (append faces (list (delete-element-of-position simplicial i))))
              (setf (gethash (delete-element-of-position simplicial i) *hash-table*) t))
            )
      )    
    )
  )

(defun faces-of-simplicial-list (list)
  (declare (cons list))
  (let ((list-of-faces '())
        (len (length list)))
    (do ((i 0 (1+ i)))
        ((= i len) list-of-faces)
      (let ((faces (faces-of-simplicial (nth i list))))
        (dolist (temp faces)
          (setf list-of-faces (append list-of-faces (list temp)))
          )
        )
      )
    )
  )

(defvar *n* 1)

(defun generate-aux (list n)
  (if (= n 1)
      (faces-of-simplicial-list list)
      (append list (generate-aux (faces-of-simplicial-list list) (1- n)))
      )
  )


(defun generate-from-maximal (simplice)
  (append (list simplice) (generate-aux (faces-of-simplicial simplice) (length simplice)))
  )


(defun simplicial-complex-generator (list)
  (clrhash *hash-table*)
  (setf *n* 1)
  (let ((aux '()))
    (dolist (temp list)
      (format t "Simplice ~A~%" *n*)
      (setf *n* (1+ *n*))
      (setf aux (append aux (generate-from-maximal temp)))
      )
    aux
    )
  )

|#

(setf torus-facets
  '((0 1 3) (0 1 5) (0 2 4)
    (0 2 6) (0 3 6) (0 4 5)
    (1 2 5) (1 2 6) (1 3 4)
    (1 4 6) (2 3 4) (2 3 5)
    (3 5 6) (4 5 6)))))


(setf torus-sc (simplicial-complex-generator torus-facets))


#|

